#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>


struct ListNode {
	int val;
	ListNode* next;
	ListNode() : val(0), next(nullptr) {}
	ListNode(int x) : val(x), next(nullptr) {}
	ListNode(int x, ListNode* next) : val(x), next(next) {}
};

ListNode* reverseList(ListNode* head) {
    ListNode* cur = head;
    ListNode* newhead = nullptr;
    while (cur)
    {
        ListNode* next = cur->next;
        cur->next = newhead;
        newhead = cur;
        cur = next;
    }
    return newhead;
}

int main()
{
    ListNode* head1 = new ListNode(1);
    ListNode* head2 = new ListNode(2);
    ListNode* head3 = new ListNode(3);
    ListNode* head4 = new ListNode(4);
    head1->next = head2;
    head2->next = head3;
    head3->next = head4;
    head4->next = nullptr;
    ListNode* newhead = reverseList(head1);
	return 0;
}